package docoffice.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import docoffice.doss.Patient;
import docoffice.doss.SysAdmin;

public class AccountLock2 extends JPanel {
	
	private JLabel title, blank, status, blank2;
	
	private JButton change;
	private String user;
	
	public AccountLock2(String username) {
		
		user = username;
		
		title = new JLabel("Lock/Unlock Account");
		blank = new JLabel();
		blank2 = new JLabel();
		
		//if account is locked
		status = new JLabel("The account is locked");
		
		//else, account is unlocked
		status = new JLabel("The account is unlocked");
		
		change = new JButton("Change account status");
		change.addActionListener(new ChangeListener());
		
		setLayout(new GridLayout(3, 2, 15, 10));
		add(title);
		add(blank);
		add(status);
		add(blank2);
		add(change);
		
		setPreferredSize(new Dimension(400, 125));
		setBackground(Color.WHITE);
	}
	
	private class ChangeListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			int value = JOptionPane.showConfirmDialog(null, "Are you sure you want to change account status?",
					"Confirm", JOptionPane.YES_NO_OPTION);
			if (value == JOptionPane.YES_OPTION) {
				SysAdmin admin = new SysAdmin("");
				final boolean isLocked = admin.isAccountLocked(user);
				if (isLocked){
					admin.unlockUser(user);
				}
				else{
					admin.lockUser(user);
				}
			}
		}
	}

}
